博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
JSP-案例-商品增删改
阅读量:4350 次
发布时间:2019-06-07

本文共 4824 字,大约阅读时间需要 16 分钟。

商品的增删改查

1显示

 

部分代码

Dao

public List
findAllProduct() throws SQLException { QueryRunner runner = new QueryRunner(DataSourceUtils.getDataSource()); String sql = "select * from product"; List
productList = runner.query(sql, new BeanListHandler
(Product.class)); return productList; }

Jsp

${vs.count }
${pro.pname } ${pro.shop_price } ${pro.is_hot==1?"是":"否" }

 

2 增

先获得分类数据

//获得所有的商品的类别数据                  AdminProductService service = new AdminProductService();                  List
categoryList = null; try { categoryList = service.findAllCategory(); } catch (SQLException e) { e.printStackTrace(); } request.setAttribute("categoryList", categoryList);

 

在显示类别

 

 

接着做数据库添加操作

public void addProduct(Product product) throws SQLException {                  QueryRunner runner = new QueryRunner(DataSourceUtils.getDataSource());                  String sql = "insert into product values(?,?,?,?,?,?,?,?,?,?)";                  runner.update(sql, product.getPid(),product.getPname(),product.getMarket_price(),                                            product.getShop_price(),product.getPimage(),product.getPdate(),product.getIs_hot(),                                            product.getPdesc(),product.getPflag(),product.getCid());                          }

3 删除

分析:你要确定你要删除的是那个,所以你要传参数,来确定你删除的是那个

Pid 来确定

Jsp

                                                                                                                                                                                                                                                                                                                                                                                                              

 

 

JS

  

function delProduct(pid){                                   var isDel = confirm("您确认要删除吗?");                                   if(isDel){                                            //要删除                                            location.href = "${pageContext.request.contextPath}/adminDelProduct?pid="+pid;                                   }                          }

 

 

4 修改

 

比较不好处理的点:商品的分类select 里面的option

1在编辑商品时需要向数据库传递你要更改的那个

2 Select里面的option默认显示是那个;

 需要option里面的value和category里面的cid进行对比(js或者jq)

 

 

Jsp里面的编辑代码

                                                                                                                                                                                                                             

 

 5 源代码

源代码:链接:https://pan.baidu.com/s/1J5u4s3emjlluZIWw7TkZmw 密码:cl9b

 

转载于:https://www.cnblogs.com/liu-wang/p/8612348.html

你可能感兴趣的文章
angular页面刷新
查看>>
Leetcode:7- Reverse Integer
查看>>
C6表单(方成eform)---自定义流程标题格式
查看>>
GridView下DropDownList 的选择方法onselectedindexchanged 实现方法
查看>>
Python之set集合
查看>>
Generic Repository Pattern - Entity Framework, ASP.NET MVC and Unit Testing Triangle
查看>>
Win7 下新版本Windows Virtual PC 安装SharePoint步骤详解
查看>>
SQLSERVER 升级版本的方法
查看>>
正则表达式基本语法详解
查看>>
BZOJ2132: 圈地计划
查看>>
PHP数据库连接mysql与mysqli的区别与用法
查看>>
char * 与char []探究理解
查看>>
QT窗体显示在屏幕中间位置
查看>>
emmet使用技巧
查看>>
RPC-Thrift(二)
查看>>
MSSQL for Linux 安装指南
查看>>
【Golang 接口自动化08】使用标准库httptest完成HTTP请求的Mock测试
查看>>
洛谷 P1036 选数
查看>>
女性社区TOP10
查看>>
BP神经网络算法推导及代码实现笔记zz
查看>>